#!/bin/bash
if [[ ! -f "$1" || "$2" == "" ]] ; then
    echo "Usage: inary-icon [inary-package] [output]"
    exit 1
fi
inaryfile=$(echo '
# Convert URI to path with python
import sys
from urllib.parse import urlparse, unquote
print(unquote(urlparse(sys.argv[1]).path))
' | python3 /dev/stdin "$1")
output="$2"
touch $output
unzip -p "$inaryfile" "icon.png" > "$output"
if [[ ! -s "$output" ]] ; then
    cat /usr/share/pixmaps/inary.png > "$output"
fi
